package ${package.Controller};

<#if formBean.staticRoute>
import ${package.Parent}.other.R;
<#else>
import com.ttxs.common.core.vo.R;
</#if>
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle?? && controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
    /**
    * 服务对象
    */
    @Resource
    private ${table.serviceName} ${table.entityPath}Service;

    /**
    * 分页查询所有数据
    *
    * @param page 分页对象
    * @param ${table.entityPath} 查询实体
    * @return 所有数据
    */
    @GetMapping
    public <#if formBean.staticRoute>R<#else>R</#if> selectAll(Page<${entity}> page, ${entity} ${table.entityPath}) {
        return <#if formBean.staticRoute>R<#else>R</#if>.ok(this.${table.entityPath}Service.page(page, new LambdaQueryWrapper<>(${table.entityPath})));
    }

    /**
    * 通过主键查询单条数据
    *
    * @param id 主键
    * @return 单条数据
    */
    @GetMapping("{id}")
    public <#if formBean.staticRoute>R<#else>R</#if> selectOne(@PathVariable Serializable id) {
        return <#if formBean.staticRoute>R<#else>R</#if>.ok(this.${table.entityPath}Service.getById(id));
    }

    /**
    * 新增数据
    *
    * @param ${table.entityPath} 实体对象
    * @return 新增结果
    */
    @PostMapping
    public <#if formBean.staticRoute>R<#else>R</#if> insert(@RequestBody ${entity} ${table.entityPath}) {
        return <#if formBean.staticRoute>R<#else>R</#if>.ok(this.${table.entityPath}Service.save(${table.entityPath}));
    }

    /**
    * 修改数据
    *
    * @param ${table.entityPath} 实体对象
    * @return 修改结果
    */
    @PutMapping
    public <#if formBean.staticRoute>R<#else>R</#if> update(@RequestBody ${entity} ${table.entityPath}) {
        return <#if formBean.staticRoute>R<#else>R</#if>.ok(this.${table.entityPath}Service.updateById(${table.entityPath}));
    }

    /**
    * 删除数据
    *
    * @param idList 主键结合
    * @return 删除结果
    */
    @DeleteMapping("{idList}")
    public <#if formBean.staticRoute>R<#else>R</#if> delete(@PathVariable("idList") List<Serializable> idList) {
        return <#if formBean.staticRoute>R<#else>R</#if>.ok(this.${table.entityPath}Service.removeByIds(idList));
    }
}
</#if>
